package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"userauthserver/proto"
	"userauthserver/tokenserver"
	"log"
)

func main () {
	con , err := grpc.Dial(":8083" ,grpc.WithInsecure())
	if err != nil {
		log.Println(err)
		return
	}
	client := userauth.NewAuthClient(con)
	rep , err := client.AuthT(context.Background() , &userauth.AuthRequest{Id: "1015286189", Password: "luhaokai"})
	if err != nil {
		log.Println(err)
	}
	if rep == nil {
		log.Println("not has this user")
		return
	}
	if !rep.IsTrue {
		log.Println("user password is default")
	}
	fmt.Println(rep.Code)
	token := Gettoken(rep.Code , "woshixiangbo" , "1")
	fmt.Println("the token is " , token)
}

func Gettoken (code , serect , clientid string) string {
	con ,err := grpc.Dial(":8082" , grpc.WithInsecure())
	if err != nil {
		log.Println(err)
		return ""
	}
	client := tokenservice.NewTokenServicesClient(con)
	rep , err := client.GetToken(context.Background() , &tokenservice.ReqGetToken{Code: code , Secret: serect , ClientId: clientid})
	if err != nil {
		log.Println(err)
		return ""
	}
	return rep.Toen
}

